package date;



import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author LIBOFEI
 * @ClassName FromToday
 * @description
 * @date 2021/7/11 14:30
 * @Version 1.0
 **/
public class FromToday {

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date date = sdf.parse("2021-07-13 12:08:09");
        fromToday(date);
    }


    public static void fromToday(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
        //现在时间
        Date now = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(now);
        int currentYear = cal.get(Calendar.YEAR);
        int currentMonth = cal.get(Calendar.MONTH) + 1;
        int currentDay = cal.get(Calendar.DAY_OF_MONTH);

        //传入时间
        Calendar param = Calendar.getInstance();
        param.setTime(date);
        int year = param.get(Calendar.YEAR);
        int month = param.get(Calendar.MONTH) + 1;
        int day = param.get(Calendar.DAY_OF_MONTH);

        //进行判断
        if(currentYear == year && month == currentMonth){
            if(currentDay == day){
                System.out.println("今天");
            }else if(currentDay - 1 == day){
                System.out.println("昨天");
            }else if(currentDay - 2 == day){
                System.out.println("前天");
            }else if(currentDay + 1 == day){
                System.out.println("明天");
            } else if(currentDay + 2 == day){
                System.out.println("后天");
            } else{
                System.out.println(sdf.format(date));
            }
        }else{
            System.out.println(sdf.format(date));
        }
    }
}
